package com.baomibing.flow.service.impl;

import com.baomibing.core.common.Assert;
import com.baomibing.flow.dto.SysFlowTrackDto;
import com.baomibing.flow.entity.SysFlowTrack;
import com.baomibing.flow.mapper.SysFlowTrackMapper;
import com.baomibing.flow.service.SysFlowTrackService;
import com.baomibing.orm.base.MBaseServiceImpl;
import com.baomibing.tool.util.Checker;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SysFlowTrackServiceImpl
 *
 * @author frog 2023/10/16 10:22
 * @version 1.0.0
 **/
@Service
public class SysFlowTrackServiceImpl extends MBaseServiceImpl<SysFlowTrackMapper, SysFlowTrack, SysFlowTrackDto> implements SysFlowTrackService {

    @Override
    public void saveTrack(SysFlowTrackDto track) {
        saveIt(track);
    }

    @Override
    public void updateTrack(SysFlowTrackDto track) {
        updateIt(track);
    }

    @Override
    public List<SysFlowTrackDto> listTrackByInstance(String instanceId) {
        if (Checker.beEmpty(instanceId)) {
            return Lists.newArrayList();
        }
        return mapper(baseMapper.selectList(lambdaQuery().eq(SysFlowTrack::getInstanceId, instanceId)));
    }

    @Override
    public void deleteByInstance(String instanceId) {
        Assert.CheckArgument(instanceId);
        baseMapper.delete(lambdaQuery().eq(SysFlowTrack::getInstanceId, instanceId));
    }

    @Override
    public void saveTracks(List<SysFlowTrackDto> tracks) {
        Assert.CheckArgument(tracks);
        saveItBatch(tracks);
    }
}
